package com.heatup.apt.common.dao;

import com.heatup.apt.model.Resource;
import com.heatup.apt.model.ResourceExample;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Component;

@Component
public interface ResourceMapper {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table resource
     *
     * @mbggenerated
     */
    int countByExample(ResourceExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table resource
     *
     * @mbggenerated
     */
    int deleteByExample(ResourceExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table resource
     *
     * @mbggenerated
     */
    @Delete({
        "delete from resource",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table resource
     *
     * @mbggenerated
     */
    @Insert({
        "insert into resource (id, res_type, ",
        "parent_type, parent_id, ",
        "res_key, title, url, ",
        " link, ",
        "view_count, like_count, ",
        "sort_num, hot, created_by, ",
        "created_time, resource_parent_id,lable,duration,video_class,status)",
        "values (#{id,jdbcType=INTEGER}, #{resType,jdbcType=CHAR}, ",
        "#{parentType,jdbcType=CHAR}, #{parentId,jdbcType=INTEGER}, ",
        "#{resKey,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, ",
        "#{link,jdbcType=VARCHAR}, #{viewCount,jdbcType=INTEGER}, ",
        "#{likeCount,jdbcType=INTEGER}, #{sortNum,jdbcType=INTEGER}, ",
        "#{hot,jdbcType=CHAR}, #{createdBy,jdbcType=INTEGER}, #{createdTime,jdbcType=TIMESTAMP}, ",
        "#{resourceParentId,jdbcType=INTEGER}, #{text,jdbcType=VARCHAR}, ",
        "#{isTop,jdbcType=CHAR}, #{duration,jdbcType=VARCHAR}, #{lable,jdbcType=VARCHAR}, ",
        "#{videoClass,jdbcType=VARCHAR},",
        "#{status,jdbcType=CHAR})"
    })
    int insert(Resource record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table resource
     *
     * @mbggenerated
     */
    int insertSelective(Resource record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table resource
     *
     * @mbggenerated
     */
    List<Resource> selectByExampleWithRowbounds(ResourceExample example, RowBounds rowBounds);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table resource
     *
     * @mbggenerated
     */
    List<Resource> selectByExample(ResourceExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table resource
     *
     * @mbggenerated
     */
    @Select({
        "select",
        "id, res_type, parent_type, parent_id, res_key, title, url, link, view_count, ",
        "like_count, sort_num, hot, created_by, created_time, resource_parent_id, text, ",
        "is_top, duration, lable, author_id, author_name, video_class,status",
        "from resource",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    Resource selectByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table resource
     *
     * @mbggenerated
     */
    int updateByExampleSelective(@Param("record") Resource record, @Param("example") ResourceExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table resource
     *
     * @mbggenerated
     */
    int updateByExample(@Param("record") Resource record, @Param("example") ResourceExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table resource
     *
     * @mbggenerated
     */
    int updateByPrimaryKeySelective(Resource record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table resource
     *
     * @mbggenerated
     */
    @Update({
        "update resource",
        "set res_type = #{resType,jdbcType=CHAR},",
          "parent_type = #{parentType,jdbcType=CHAR},",
          "parent_id = #{parentId,jdbcType=INTEGER},",
          "res_key = #{resKey,jdbcType=VARCHAR},",
          "title = #{title,jdbcType=VARCHAR},",
          "url = #{url,jdbcType=VARCHAR},",
          "link = #{link,jdbcType=VARCHAR},",
          "view_count = #{viewCount,jdbcType=INTEGER},",
          "like_count = #{likeCount,jdbcType=INTEGER},",
          "sort_num = #{sortNum,jdbcType=INTEGER},",
          "hot = #{hot,jdbcType=CHAR},",
          "created_by = #{createdBy,jdbcType=INTEGER},",
          "created_time = #{createdTime,jdbcType=TIMESTAMP},",
          "resource_parent_id = #{resourceParentId,jdbcType=INTEGER},",
          "text = #{text,jdbcType=VARCHAR},",
          "is_top = #{isTop,jdbcType=CHAR},",
          "duration = #{duration,jdbcType=VARCHAR},",
          "lable = #{lable,jdbcType=VARCHAR},",
          "author_id = #{authorId,jdbcType=INTEGER},",
          "author_name = #{authorName,jdbcType=VARCHAR},",
          "video_class = #{videoClass,jdbcType=VARCHAR},",
          "status = #{status,jdbcType=CHAR}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Resource record);

    /**
     * 根据标准课程ID删除关联资源
     *
     * @param id
     * @return
     */
    @Delete({
            "delete from resource",
            "where parent_type = 4 and parent_id = #{id}"
    })
    int deleteByCourseStandardId(int id);

    /**
     * 根据门店ID删除关联资源
     *
     * @param id
     * @return
     */
    @Delete({
            "delete from resource",
            "where parent_type = 1 and parent_id = #{id}"
    })
    int deleteByStoreId(Integer id);

    /**
     * 根据教练ID删除关联资源
     *
     * @param id
     * @return
     */
    @Delete({
            "delete from resource",
            "where parent_type = 3 and parent_id = #{id}"
    })
    int deleteByCoachId(Integer id);

    /**
     * 根据课程ID删除关联资源
     *
     * @param id
     * @return
     */
    @Delete({
            "delete from resource",
            "where parent_type = 2 and parent_id = #{id}"
    })
    int deleteByCourseId(Integer id);
    
    List<Resource> queryResourceByStoreId(int storeId);

    /**
     * 查询教练私教案例资源
     *
     * @param id
     * @return
     */
    Resource queryCoachPrivateSampleByCoachId(Integer id);
}